package com.jiyun.controller;

import com.github.pagehelper.PageInfo;
import com.jiyun.common.dto.R;
import com.jiyun.common.pojo.Goods;
import com.jiyun.common.pojo.Sales;
import com.jiyun.service.SalesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sales")
public class SalesController {
    @Autowired
    private SalesService salesService;
    @PostMapping("/findPage")
    public R findPage(@RequestParam(defaultValue = "1")Integer page,
                      @RequestParam(defaultValue = "2")Integer pageSize,
                      @RequestBody Sales sales){
        PageInfo<Sales> pageInfo = salesService.findPage(page, pageSize, sales);
        return R.success(pageInfo);
    }
    @PostMapping("/save")
    public R save(@RequestBody Sales sales){
        if (sales.getId() == null){
            salesService.save(sales);
        }else{
            salesService.update(sales);
        }
        return R.successL();
    }
    @GetMapping("/findGoods")
    public List<Goods> findGoods(){
        return salesService.findGoods();
    }
}
